/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entities;

import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author damfercer
 */
@Entity
@Table(name = "candidate_language_info")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "CandidateLanguageInfo.findAll", query = "SELECT c FROM CandidateLanguageInfo c ORDER BY c.languageLevel.value DESC"),
    @NamedQuery(name = "CandidateLanguageInfo.findByIdCandidateLanguageInfo", query = "SELECT c FROM CandidateLanguageInfo c WHERE c.idCandidateLanguageInfo = :idCandidateLanguageInfo"),
    @NamedQuery(name = "CandidateLanguageInfo.findBestVideoFromCandidate", query = "SELECT c FROM CandidateLanguageInfo c WHERE c.candidate = :candidate AND c.video IS NOT NULL ORDER BY c.languageLevel.value DESC"),
    @NamedQuery(name = "CandidateLanguageInfo.findByVideo", query = "SELECT c FROM CandidateLanguageInfo c WHERE c.video = :video")})
public class CandidateLanguageInfo implements Serializable {
    @Size(max = 100)
    @Column(name = "DESCRIPTION")
    private String description;
    @JoinColumn(name = "WRITING_LEVEL", referencedColumnName = "ID_LANGUAGE_LEVEL")
    @ManyToOne(optional = false)
    private LanguageLevel writingLevel;
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "ID_CANDIDATE_LANGUAGE_INFO")
    private Integer idCandidateLanguageInfo;
    @Size(max = 128)
    @Column(name = "VIDEO")
    private String video;
    @JoinColumn(name = "LANGUAGE_LEVEL", referencedColumnName = "ID_LANGUAGE_LEVEL")
    @ManyToOne
    private LanguageLevel languageLevel;
    @JoinColumn(name = "LANGUAGE", referencedColumnName = "ID_LANGUAGE")
    @ManyToOne(optional = false)
    private Language language;
    @JoinColumn(name = "CANDIDATE", referencedColumnName = "ID_CANDIDATE")
    @ManyToOne(optional = false)
    private Candidate candidate;

    public CandidateLanguageInfo() {
    }

    public CandidateLanguageInfo(Integer idCandidateLanguageInfo) {
        this.idCandidateLanguageInfo = idCandidateLanguageInfo;
    }

    public Integer getIdCandidateLanguageInfo() {
        return idCandidateLanguageInfo;
    }

    public void setIdCandidateLanguageInfo(Integer idCandidateLanguageInfo) {
        this.idCandidateLanguageInfo = idCandidateLanguageInfo;
    }

    public String getVideo() {
        return video;
    }

    public void setVideo(String video) {
        this.video = video;
    }

    public LanguageLevel getLanguageLevel() {
        return languageLevel;
    }

    public void setLanguageLevel(LanguageLevel languageLevel) {
        this.languageLevel = languageLevel;
    }

    public Language getLanguage() {
        return language;
    }

    public void setLanguage(Language language) {
        this.language = language;
    }

    public Candidate getCandidate() {
        return candidate;
    }

    public void setCandidate(Candidate candidate) {
        this.candidate = candidate;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idCandidateLanguageInfo != null ? idCandidateLanguageInfo.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        boolean res=false;
        if (object instanceof CandidateLanguageInfo) {
            CandidateLanguageInfo other=(CandidateLanguageInfo)object;
            if(this.getIdCandidateLanguageInfo()!=null && other.getIdCandidateLanguageInfo()!=null){
                res=this.getIdCandidateLanguageInfo().equals(other.getIdCandidateLanguageInfo());
            }
            else{
                /*if(this.getVideo()!=null && other.getVideo()!=null){
                    res=this.getLanguage().getIdLanguage().equals(other.getLanguage().getIdLanguage()) && this.getLanguageLevel().getIdLanguageLevel().equals(other.getLanguageLevel().getIdLanguageLevel()) && this.getVideo().equals(other.getVideo());
                }
                else{*/
                    res=this.getLanguage().getIdLanguage().equals(other.getLanguage().getIdLanguage());
                //}
            }
        }
        return res;
    }

    @Override
    public String toString() {
        return "entities.CandidateLanguageInfo[ idCandidateLanguageInfo=" + idCandidateLanguageInfo + " ]";
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public LanguageLevel getWritingLevel() {
        return writingLevel;
    }

    public void setWritingLevel(LanguageLevel writingLevel) {
        this.writingLevel = writingLevel;
    }
    
}
